<%@page contentType="text/html; charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp" %>
<html>
	<head>
		<title>角色权限授予</title>
		<link rel="stylesheet" href="${ctxPath}/resource/common/css/jquery.treeview.css" />
		<script type="text/javascript" src="${ctxPath}/resource/common/js/jquery/ui/jquery.treeview.js"></script>
		<script src="${ctxPath}/resource/common/js/jquery/jquery.metadata.js" type="text/javascript"></script>
		<script type="text/javascript">
			<c:set var="ids" value=""/>
			<c:forEach items="${appRole.resources}" var="rs">
				<c:set var="ids">
					${ids}<c:if test="${ids!=''}">,</c:if>${rs.resourceId}
				</c:set>
			</c:forEach>
			var checkIds=[${ids}];
			$(function(){
				$("#rightTreeview").treeview({control:"#treeview-controller",animated: "fast"});
				$.metadata.setType("attr", "path");
				//checkbocx选择，允许上级选择连带下级选择。
				$("li > span > input").click(function(){
					var curId=this.value;
					var _path=$(this).attr("path");
					if(_path=="null"){
						_path=curId;
					}else{
						_path+="."+curId;
					}
					var checked=this.checked;
					$("input[name='resourceId']").each(function(i){
						var path=$(this).attr("path");
						if(path.lastIndexOf(_path)!=-1){
							this.checked=checked;
						}
					}); 
				});
				
				//连接显示
				$("#rightTreeview li > span > a").click(function(){
					$("#resourceDetail").load(__ctxPath+"/admin/system/appResources.do?decorator=blank&cmd=viewDetail&resourceId="+$(this).prev().val(),
					function(){});
				});
				
				//加载已经选择了的权限
				if(checkIds.length>0){
					$("input[name='resourceId']").each(function(i){
						for(var i=0;i<checkIds.length;i++){
							if(this.value==checkIds[i]){
								this.checked=true;
								return;
							}
						}
					}); 
				}
			});
		</script>
	</head>
	<body>
		<div id="div-data">
			<form action="grantRight.do?cmd=saveGrantRight" method="post">
				<table width="96%" cellpadding="0" cellspacing="0" align="center">
					<thead>
						<tr>
							<th colspan="2">[${appRole.roleName}]角色权限授予</th>
						</tr>
					</thead>
					<tbody>
						<tr class="odd">
							<td width="35%" valign="top">
								<div id="treeview-controller">
									<a href="#" class="collapse">全部收起</a>
									<a href="#" class="expand">全部展开</a>
									<a href="#" class="toggle">展 缩</a>
								</div>
								${treeMenus}
							</td>
							<td width="65%" valign="top">
								<div id="resourceDetail">
								</div>
							</td>
						</tr>
						<tr>
							<td colspan="2" align="center">
								<input type="submit" value="保 存" class="save">
							</td>
						</tr>
					</tbody>
				</table>
				<input type="hidden" name="roleId" value="${param['roleId']}"/>
			</form>
		</div>
	</body>
</html>